/*
 * syncmlbt.h - SyncMLbt library interface - sync phonebook
 *
 * Copyright (C) 2010-2011 Serge Begger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SYNCMLBT_H
#define SYNCMLBT_H

#include <QObject>
#include <QTimer>
#include <QTextCodec>
#include <libsyncml/syncml.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

#include "qcarpcdialog.h"

typedef struct selfbt {
    bool *startSync;
    bool *endSync;
    bool *error;
    char *errmsg;
} selfbt;

class syncmlbt : public QObject
{
    Q_OBJECT

public:
    explicit syncmlbt(QObject *parent = 0);
    void startSync();
    bool search(QString);
    QList<QByteArray> *vCards;

signals:
    void endSync();

public slots:

private:
    myMessage *message;
    myProgressbar *progressbar;
    SmlDataSync *dsObject;
    SmlDataSyncDataStore *datastore;

    static void smlDataRecvEventCallback(SmlDataSyncSession *session,
                                SmlDataSync *dsObject,
                                SmlDataSyncEventType type,
                                void *userdata,
                                const GError *error);
    //callback datastore
    static SmlAlertType smlDataSyncAlert (SmlDataSyncDataStoreSession *session,
                                    SmlAlertType type,
                                    void *userdata,
                                    GError **error);

    static gboolean smlDataSyncChange (SmlDataSyncDataStoreSession *session,
                                 SmlDataSyncChangeItem *item,
                                 void *userdata,
                                 GError **error);

    static gboolean smlDataSyncChangeStatus(SmlDataSyncDataStoreSession *session,
                                                 SmlDataSyncChangeItem *item,
                                                 SmlErrorType code,
                                                 void *userdata,
                                                 GError **error);

    static gboolean smlDataSyncMappingCallback(SmlDataSyncDataStoreSession *session,
                                                    SmlMapItem *item,
                                                    void *userdata,
                                                    GError **error);

    selfbt *selfData;
    QTimer *timerSinc;
    QString btaddress;
    bool initSML();

    static bdaddr_t interface;

private slots:
    void parseEvent();

};

#endif // SYNCMLBT_H
